package edu.iss.demo.web.controller;


import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import edu.iss.demo.model.LeaveApplication;
import edu.iss.demo.service.LeaveApplicationService;



@Controller
public class EmployeeController 
{
	
	@Autowired
	LeaveApplicationService leaveAppService;
	
	//Employee Navigation Controller
	@RequestMapping(value = "/employee", method = RequestMethod.GET)
	public ModelAndView empView()
	{
		return new ModelAndView("emp_leave");
	}
	
	@RequestMapping(value = "/employee/info", method = RequestMethod.GET)
	public ModelAndView empInfo()
	{
		return new ModelAndView("employeeInfo");
	}
	@RequestMapping(value = "/employee/request-attendance", method = RequestMethod.GET)
	public ModelAndView empRA()
	{
		return new ModelAndView("emp_requestAttendance");
	}
	@RequestMapping(value = "/employee/Leavehistory-Approved", method = RequestMethod.GET)
	public ModelAndView empRLH()
	{
		return new ModelAndView("emp_approvedLeaveHistory");
	}
	@RequestMapping(value ="/employee/Leavehistory-Appending", method = RequestMethod.GET)
	public ModelAndView empLHA()
	{
		return new ModelAndView("emp_appendingLeaveHistory");
	}
	@RequestMapping(value ="/employee/Leavehistory-Reject", method = RequestMethod.GET)
	public ModelAndView empLHR()
	{
		return new ModelAndView("emp_rejectLeaveHistory");
	}
	
	@RequestMapping(value="/employee/Leave-Form", method=RequestMethod.GET)
	public ModelAndView addLeaveAppDisplay()
	{
		ModelAndView mav = new ModelAndView("emp_leave","leaveAppliation",new LeaveApplication());
		return mav;
	}

/*	@RequestMapping(value="/employee/leaveform", method=RequestMethod.POST,params="save")
	public ModelAndView addLeaveApp(@ModelAttribute LeaveApplication la, ModelMap model, WebRequest webRequest)
	{
		leaveAppService.create(la);
		System.out.print(la.getLeaveType());
		System.out.println(la.getEmployeeComment());
		System.out.println(la.getFromDate());
		
		
	}
		
	*/
	
	
	
	@RequestMapping(value = "/employee/success", method = RequestMethod.POST)
	public ModelAndView addLeaveApp(
			@ModelAttribute @Valid LeaveApplication la, BindingResult result,
			final RedirectAttributes redirectAttributes, WebRequest webRequest)
	{
		

		ModelAndView mav = new ModelAndView();
		leaveAppService.create(la);
		mav.setViewName("TESTMAI");
		return mav;
	}
	
	

}
